package org.dstart.draw.cui.symbol.basic
{
	import flash.display.CapsStyle;
	import flash.display.JointStyle;
	import flash.display.LineScaleMode;
	import flash.display.Sprite;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;
	import flash.geom.Rectangle;
	
	import org.dstart.draw.cglobal.GColors;
	import org.dstart.draw.cglobal.GValue;
	import org.dstart.draw.csuper.CSprite;
	import org.dstart.draw.iface.IDraw;	

	public class BWindowBackground extends CSprite implements IDraw
	{
		private var m_width:Number;		//	基础宽度
		private var m_height:Number;	//	基础高度
		
		private var initFlag:Boolean;	//	是否初始化
		
		public function BWindowBackground(w:Number = 400, h:Number = 300)
		{
			InitObject();
			ChangeSize(w, h);				
		}
		
		//	修改大小
		public function ChangeSize(w:Number, h:Number):void
		{
			m_width = w;
			m_height = h;

			RushObject();
		}
		
		//	返回可绘图区域（返回外部可绘图的区域）
		public function get rect():Rectangle
		{
			return new Rectangle(this.sprMain.x, this.sprMain.y, this.sprMain.width, this.sprMain.height);
		}
		
		//-------------------------------------------------------------
		
		private var sprFilter:Sprite;	//	外框效果对象
		private var sprLine:Sprite;		//	边框响应区（用于拖动时修改大小)
		private var sprAlpha:Sprite;	//	透明区块
		private var sprMain:Sprite;		//	主区块	
		
		private function InitObject():void
		{
			initFlag = true;
						
			sprFilter = new Sprite();
			sprLine = new Sprite();
			sprAlpha = new Sprite();
			sprMain = new Sprite();
			
			_root.addChild(sprFilter);
			_root.addChild(sprLine);
			_root.addChild(sprAlpha);
			_root.addChild(sprMain);
		}
		
		private function RushObject():void
		{
			var lc:uint = GColors.WIN_BG_LINE_COLOR;
			var fhc:uint = GColors.WIN_BG_HFILL_COLOR;
			var flc:uint = GColors.WIN_BG_LFILL_COLOR;
			var ftc:uint = GColors.WIN_FILTER_COLOR;
			var fmc:uint = GColors.WIN_BG_MFILL_COLOR;
			var r:Number = GValue.DEF_ROUND_SIZE;
			
			this.sprFilter.graphics.clear();
			this.sprFilter.graphics.beginFill(lc, 1);
			this.sprFilter.graphics.drawRoundRectComplex(0, 0, this.m_width, this.m_height, r, r, r, r);
			this.sprFilter.graphics.endFill();
			
			this.sprFilter.filters = new Array(new GlowFilter(ftc, 1, 8, 8, 1, BitmapFilterQuality.HIGH, false, true));
			
			this.sprLine.graphics.clear();
			this.sprLine.graphics.lineStyle(3, lc, 1, true, LineScaleMode.NONE, CapsStyle.ROUND, JointStyle.ROUND);
			this.sprLine.graphics.drawRoundRectComplex(0, 0, m_width, m_height, r,r,r,r);
						
			this.sprAlpha.graphics.clear();
			this.sprAlpha.graphics.beginFill(flc, .3);
			this.sprAlpha.graphics.drawRoundRectComplex(1, 1, m_width-2, m_height-2, r-2, r-2, r-2, r-2);
			this.sprAlpha.graphics.endFill();
			
			this.sprMain.graphics.clear();			
			this.sprMain.graphics.beginFill(fmc, 1);
			this.sprMain.graphics.lineStyle(1, lc, .5, true, LineScaleMode.NONE, CapsStyle.ROUND, JointStyle.ROUND);
			this.sprMain.graphics.drawRoundRectComplex(0, 0, m_width - 20, m_height - 20, r - 3, r - 3, r - 3, r - 3);
			this.sprMain.graphics.endFill();
			
			this.sprMain.x = 10;
			this.sprMain.y = 10;
		}
	}
}